#!/bin/bash

# 创建 /opt/FileCodeBox 目录
echo "创建 /opt/FileCodeBox 目录..."
mkdir -p /opt/FileCodeBox
chmod -R 755 /opt/FileCodeBox

# 更新系统包
echo "更新系统包..."
apt-get update
apt-get upgrade -y

# 安装 Docker
echo "安装 Docker..."
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io

# 启动 Docker 服务
echo "启动 Docker 服务..."
systemctl start docker
systemctl enable docker

# 拉取并运行 FileCodeBox 容器
echo "拉取并运行 FileCodeBox 容器..."
docker run -d \
  --restart=always \
    -p 12345:12345 \
      -v /opt/FileCodeBox:/app/data \
        --name filecodebox \
          lanol/filecodebox:beta

          # 检查容器是否运行
          echo "检查容器状态..."
          docker ps -f name=filecodebox

          # 输出部署信息
          echo "文件快递柜部署完成！"
          echo "FileCodeBox 已成功部署到 Docker 容器中。"
          echo "访问地址: http://<服务器IP或域名>:12345"
          echo "文件存储目录: /opt/FileCodeBox"